//
//  RequestPopupView.m
//  aigo
//
//  Created by Tai Truong on 12/26/12.
//  Copyright (c) 2012 AIGO. All rights reserved.
//

#import "RequestPopupView.h"

@implementation RequestPopupView

- (id)initWithNotificationType:(enumRemoveNotificationType)type
{
    self.notificationType = type;
    
    switch (self.notificationType) {
        case enumRemoveNotificationType_ClientRequestDriver:
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:0];
            break;
        case enumRemoveNotificationType_DriverAcceptTheRequest:
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:1];
            break;
        case enumRemoveNotificationType_DriverNotifyYourArrivalDriverPopup:
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:2];
            break;
        case enumRemoveNotificationType_DriverNotifyYourArrivalClientPopup:
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:3];
            break;
        case enumRemoveNotificationType_ClientCountDownPopup:
        case enumRemoveNotificationType_DriverCountDownPopup:
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:4];
            break;
        case enumRemoveNotificationType_CancelThisTransation:
        {
#ifdef __CLIENT__
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:5];
#else
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:6];
#endif
            break;
        }
        case enumRemoveNotificationType_DriverSendBillPopup:
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:7];
            break;
        case enumRemoveNotificationType_ClientReceiveBillPopup:
            _viewPopUp = [[[NSBundle mainBundle] loadNibNamed:[self.class description] owner:self options:nil] objectAtIndex:8];
            break;
            
        default:
            break;
    }
    
    if (self) {
    }
    return self;
}

- (IBAction)touchUpInsideAccept:(UIButton *)sender {
    if ([_delegate respondsToSelector:@selector(touchUpInsideAcceptRequestPopupCallbackWithNotificationType:)]) {
        [_delegate touchUpInsideAcceptRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

- (IBAction)touchUpInsideReject:(UIButton *)sender {
    if ([_delegate respondsToSelector:@selector(touchUpInsideRejectRequestPopupCallbackWithNotificationType:)]) {
         [_delegate touchUpInsideRejectRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

- (IBAction)touchUpInsideAround:(id)sender {
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    
    if ([_delegate respondsToSelector:@selector(touchUpInsideAroundRequestPopupCallbackWithNotificationType:)]) {
        [_delegate touchUpInsideAroundRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

- (IBAction)touchUpInsideOK:(id)sender {
    if ([_delegate respondsToSelector:@selector(touchUpInsideOKRequestPopupCallbackWithNotificationType:)]) {
        [_delegate touchUpInsideOKRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

- (IBAction)touchUpInsideSend:(id)sender {
    if ([_delegate respondsToSelector:@selector(touchUpInsideSendRequestPopupCallbackWithNotificationType:)]) {
        [_delegate touchUpInsideSendRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

- (IBAction)touchUpInsideCancel:(id)sender {
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    
    if ([_delegate respondsToSelector:@selector(touchUpInsideOKRequestPopupCallbackWithNotificationType:)]) {
        [_delegate touchUpInsideCancelRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

- (IBAction)touchUpInsideSendBill:(id)sender {
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    
    if ([_delegate respondsToSelector:@selector(touchUpInsideSendBillRequestPopupCallbackWithNotificationType:andAmount:)]) {
        [_delegate touchUpInsideSendBillRequestPopupCallbackWithNotificationType:self.notificationType andAmount:(NSString *)_textFieldMeterAmount.text];
    }
}

- (IBAction)touchUpInsideCharge:(id)sender {
    if ([_delegate respondsToSelector:@selector(touchUpInsideChargeRequestPopupCallbackWithNotificationType:)]) {
        [_delegate touchUpInsideChargeRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

- (IBAction)touchUpInsideCash:(id)sender {
    if ([_delegate respondsToSelector:@selector(touchUpInsideCashRequestPopupCallbackWithNotificationType:)]) {
        [_delegate touchUpInsideCashRequestPopupCallbackWithNotificationType:self.notificationType];
    }
}

#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if ([_delegate respondsToSelector:@selector(touchUpInsideSendBillRequestPopupCallbackWithNotificationType:)] && textField == _textFieldMeterAmount) {
        [_delegate touchUpInsideSendBillRequestPopupCallbackWithNotificationType:self.notificationType andAmount:(NSString *)_textFieldMeterAmount.text];
    }
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
}

@end
